﻿Imports Microsoft.VisualStudio.TestTools.UnitTesting.Web

Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Data


'''<summary>
'''This is a test class for functionsTest and is intended
'''to contain all functionsTest Unit Tests
'''</summary>
<TestClass()> _
Public Class functionsTest


    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = Value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''A test for upload
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub uploadTest()
        Dim str As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim catid As String = "1"
        Dim title As String = "superb pic"
        Dim description As String = "legby applealing"
        Dim imgurl As String = "uploads/0821201084057PM.jpg"
        Dim uploadedby As String = "admin"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()

        Dim cmd As New SqlCommand("select count(*) from imagetable", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)

        str = "insert into imagetable(categoryid,title,description,imageurl,uploaddate,uploadby,likes,dislikes) values(" + catid + ",'" + title + "','" + description + "','" + imgurl + "','" + DateTime.Now + "','" + uploadedby + "',0,0)"
        actual = functions_Accessor.upload(str)
        actual = Integer.Parse(cmd.ExecuteScalar().ToString)
        Assert.AreEqual(expected + 1, actual)
        Dim del As New SqlCommand("delete from imagetable where imageid=(select max(imageid) from imagetable)", cn)
        del.ExecuteNonQuery()

        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for updateprofile
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub updateprofileTest()
        Dim str As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim emailid As String = "r_i_s_h_i_143@yahoo.com"
        Dim question As String = "My school name"
        Dim answer As String = "divinebuds"
        Dim username = "rp09aas"
        str = "update users set emailid='" + emailid + "', question='" + question + "',answer='" + answer + "' where username='" + username
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        Dim cmd As SqlCommand
        cmd = New SqlCommand(str + "'", cn)
        cn.Open()
        expected = cmd.ExecuteNonQuery()
        actual = functions_Accessor.updateprofile(str)
        Assert.AreEqual(expected, actual)

        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for sendmessage
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
   Public Sub sendmessageTest()
        Dim str As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer

        Dim sampleMessage As String = "insert into message(receiver,sender,message,date) values('" + "Admin" + "','" + "Rishi" + "','" + "Hello" + "','" + DateTime.Now.Date + "')"
        ' find the number of messages currently in the message table
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim cmd As New SqlCommand("select count(*) from message", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)


        actual = functions_Accessor.sendmessage(sampleMessage)

        Dim newcmd As New SqlCommand("select count(*) from message", cn)
        actual = Integer.Parse(newcmd.ExecuteScalar().ToString)


        Assert.AreEqual(expected + 1, actual)
        
        Dim del As New SqlCommand("delete from message where msgid=(select max(msgid) from message)", cn)
        del.ExecuteNonQuery()
        cn.Close()

        'second testing
        Dim message As String = "hello mr's how r u"
        Dim secondMessage As String = "insert into message(receiver,sender,message,date) values('" + "Admin" + "','" + "Rishi" + "','" + message + "','" + DateTime.Now.Date + "')"
        cn.Open()
        Dim cmd2 As New SqlCommand("select count(*) from message", cn)
        expected = Integer.Parse(cmd2.ExecuteScalar().ToString)


        actual = functions_Accessor.sendmessage(sampleMessage)

        Dim newcmd2 As New SqlCommand("select count(*) from message", cn)
        actual = Integer.Parse(newcmd2.ExecuteScalar().ToString)


        Assert.AreEqual(expected + 1, actual)

        Dim del2 As New SqlCommand("delete from message where msgid=(select max(msgid) from message)", cn)
        del2.ExecuteNonQuery()
        cn.Close()

        'delete top 1 from messages
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub


    '''<summary>
    '''A test for sendmail
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub sendmailTest()
        Dim a As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim txtEmail As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 1 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        a = "rp09aas"
        txtEmail = "r_i_s_h_i_143@yahoo.com"
        actual = functions_Accessor.sendmail(a, txtEmail)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for registration
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub registrationTest()
        Dim str As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim cmd As New SqlCommand("select count(*) from users", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)

        str = "insert into users values('" + "testuser" + "','" + "testuser" + "','" + "Testusername" + "','" + "testusersecondname" + "','" + DateTime.Now.ToString() + "','" + "testlocation" + "','" + "08/20/2010" + "','" + "M" + "','" + "test@yahoo.com" + "','" + "testquestion" + "','" + "testanswer" + "','allowed');"
        actual = functions_Accessor.registration(str)
        Dim newcmd As New SqlCommand("select count(*) from users", cn)
        actual = Integer.Parse(newcmd.ExecuteScalar().ToString)

        Assert.AreEqual(expected + 1, actual)
        'Dim t As String = "testuser"
        'Dim deluser As New SqlCommand("delete from users where username=" + t.ToLower, cn)
        'deluser.ExecuteNonQuery()
        'cn.Close()
        ' Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for negratting
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub negrattingTest()
        Dim ids As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        '106 image id
        ids = "106"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim cmd As New SqlCommand("select dislikes from imagetable where imageid=" + ids, cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)

        Dim actual As Integer

        actual = functions_Accessor.negratting(ids)
        Dim newcmd As New SqlCommand("select dislikes from imagetable where imageid=" + ids, cn)
        actual = Integer.Parse(newcmd.ExecuteScalar().ToString)

        Assert.AreEqual(expected + 1, actual)

        Dim del As New SqlCommand("update imagetable set dislikes=dislikes-1 where imageid=" + ids, cn)
        del.ExecuteNonQuery()
        cn.Close()
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub
    

    '''<summary>
    '''A test for logout
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub logoutTest()
        Dim sqlcmd As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim username As String = "rp09aas"
        sqlcmd = ("update users set logindate='" + DateTime.Now + "' where username='" + username + "'")
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim cmd As SqlCommand = New SqlCommand(sqlcmd, cn)
        expected = cmd.ExecuteNonQuery()
        cn.Close()
        actual = functions_Accessor.logout(sqlcmd)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for login
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub loginTest()
        Dim txtusername As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim txtpassword As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim sessionuser As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        txtusername = "admin"
        txtpassword = "admin"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        Dim str As String = "select count(*) from users where username='" + txtusername + "' and password = '" + txtpassword + "'"
        Dim cmd As New SqlCommand(str, cn)
        cn.Open()
        If cmd.ExecuteScalar = 1 Then
            cn.Close()
            cn.Open()
            cmd = New SqlCommand("select banned from users where username='" + txtusername + "'", cn)
            If (cmd.ExecuteScalar = "allowed") Then
                sessionuser = txtusername
                expected = 1
            Else
                expected = 0
            End If
        Else
            expected = -1

        End If
        actual = functions_Accessor.login(txtusername, txtpassword, sessionuser)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for forgotpassword
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub forgotpasswordTest()
        Dim username As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim userans As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        username = "rp09aas"
        userans = "divine buds"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        Dim cmd As New SqlCommand("select answer from users where username='" + username + "'", cn)
        cn.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader
        dr.Read()
        Dim ans As String = dr("answer")
        cn.Close()

        If (ans.ToLower = userans) Then
            expected = 1
        Else
            expected = 0
        End If
        actual = functions_Accessor.forgotpassword(username, userans)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for deluser
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub deluserTest()
        Dim uname As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim status As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        uname = "rp09aas"
        status = "allowed"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        If status = "allowed" Then
            Dim cmd As New SqlCommand("update users set banned='banned' where username='" + uname + "'", cn)
            expected = cmd.ExecuteNonQuery()
        Else
            Dim cmd As New SqlCommand("update users set banned='allowed' where username='" + uname + "'", cn)
            expected = cmd.ExecuteNonQuery()
        End If
        cn.Close()
        status = "banned"
        actual = functions_Accessor.deluser(uname, status)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for delmessages
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub delmessagesTest()

        Dim str As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim sampleMessage As String = "insert into message(receiver,sender,message,date) values('" + "Admin" + "','" + "Rishi" + "','" + "Hello" + "','" + DateTime.Now.Date + "')"
        ' find the number of messages currently in the message table
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        expected = functions_Accessor.sendmessage(sampleMessage) 'adding new message
        Dim cmd As New SqlCommand("select count(*) from message", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)
        Dim msgid As String
        Dim msg As New SqlCommand("select max(msgid) from message", cn)
        msgid = msg.ExecuteScalar().ToString
        str = "delete from message where msgid=" + msgid
        actual = functions_Accessor.delmessages(str)
        actual = Integer.Parse(cmd.ExecuteScalar().ToString)
        Assert.AreEqual(expected, actual + 1)

        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for deletepicture
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub deletepictureTest()
        Dim a As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0  ' TODO: Initialize to an appropriate value
        Dim actual As Integer = 0
        Dim catid As String = "1"
        Dim title As String = "superb pic"
        Dim description As String = "legby applealing"
        Dim imgurl As String = "uploads/0821201084057PM.jpg"
        Dim uploadedby As String = "admin"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim str As String
        Dim temp As String
        str = "insert into imagetable(categoryid,title,description,imageurl,uploaddate,uploadby,likes,dislikes) values(" + catid + ",'" + title + "','" + description + "','" + imgurl + "','" + DateTime.Now + "','" + uploadedby + "',0,0)"
        temp = functions_Accessor.upload(str)
        'image uploaded
        Dim cmd As New SqlCommand("select count(*) from imagetable", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString) 'total number of images
        Dim msgid As String
        Dim msg As New SqlCommand("select max(imageid) from imagetable", cn)
        msgid = msg.ExecuteScalar().ToString

        temp = functions_Accessor.deletepicture(msgid)

        actual = Integer.Parse(cmd.ExecuteScalar().ToString)
        
        Assert.AreEqual(expected, actual + 1)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for delcomment
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub delcommentTest()
        Dim A As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()

        Dim imgid As String = "106"
        Dim username As String = "admin"
        Dim comment As String = "good pic"
        A = "insert into comment(imageid,commentby,comment,cdate) values('" + imgid + "','" + username + "','" + comment + "','" + DateTime.Now
        expected = functions_Accessor.addcomments(A)
        Dim cmd As New SqlCommand("select count(*) from comment", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)
        Dim del As New SqlCommand("select max(commentid) from comment", cn)
        A = del.ExecuteScalar()
        actual = functions_Accessor.delcomment(A)
        actual = Integer.Parse(cmd.ExecuteScalar().ToString)
        Assert.AreEqual(expected, actual + 1)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for check
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub checkTest()
        Dim str As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        str = "rp09aas"
        str = ("select count(*) from users where username='" + str + "'")
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim cmd As SqlCommand = New SqlCommand(str, cn)

        If cmd.ExecuteScalar = 1 Then
            ' so it means user exists
            expected = 1
        Else
            expected = 0
        End If
        cn.Close()
        actual = functions_Accessor.check(str)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for changepassword
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub changepasswordTest()
        Dim a As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim password As String
        password = "rishi123"
        Dim username As String = "rp09aas"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        a = "update users set password='" + password + "' where username='" + username
        Dim cmd As New SqlCommand(a + "'", cn)
        cn.Open()
        expected = cmd.ExecuteNonQuery()
        cn.Close()
        actual = functions_Accessor.changepassword(a)
        Assert.AreEqual(expected, actual)
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for addratting
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub addrattingTest()
        Dim ids As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        '106 image id
        ids = "106"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        Dim cmd As New SqlCommand("select likes from imagetable where imageid=" + ids, cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)

        Dim actual As Integer
        ids = "106"
        actual = functions_Accessor.addratting(ids)
        Dim newcmd As New SqlCommand("select likes from imagetable where imageid=" + ids, cn)
        actual = Integer.Parse(newcmd.ExecuteScalar().ToString)

        Assert.AreEqual(expected + 1, actual)
        Dim del As New SqlCommand("update imagetable set likes=likes-1 where imageid=" + ids, cn)
        del.ExecuteNonQuery()
        cn.Close()
        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for addcomments
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub addcommentsTest()
        Dim a As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()

        Dim imgid As String = "107"
        Dim username As String = "admin"
        Dim comment As String = "good pic"
        a = "insert into comment(imageid,commentby,comment,cdate) values('" + imgid + "','" + username + "','" + comment + "','" + DateTime.Now
        Dim cmd As New SqlCommand("select count(*) from comment", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)

        actual = functions_Accessor.addcomments(a)
        actual = Integer.Parse(cmd.ExecuteScalar().ToString)
        Assert.AreEqual(expected + 1, actual)

        Dim del As New SqlCommand("delete from comment where commentid=(select max(commentid) from comment)", cn)
        del.ExecuteNonQuery()
        cn.Close()

        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for addcategory
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub addcategoryTest()
        Dim a As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim expected As Integer = 0 ' TODO: Initialize to an appropriate value
        Dim actual As Integer
        Dim newcategory As String = "newcat"
        Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Database.mdf';Integrated Security=True;User Instance=True")
        cn.Open()
        a = "insert into category(name) values('" + newcategory.Trim
        Dim cmd As New SqlCommand("select count(*) from category", cn)
        expected = Integer.Parse(cmd.ExecuteScalar().ToString)
        actual = functions_Accessor.addcategory(a)
        actual = Integer.Parse(cmd.ExecuteScalar().ToString)
        Assert.AreEqual(expected + 1, actual)
        Dim del As New SqlCommand("delete from category where categoryid=(select max(categoryid) from category)", cn)
        del.ExecuteNonQuery()
        cn.Close()

        'Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for functions Constructor
    '''</summary>
    <TestMethod(), _
     HostType("ASP.NET"), _
     AspNetDevelopmentServerHost("%PathToWebRoot%\Desktop\rishi project new", "/rishi project new"), _
     UrlToTest("http://localhost/rishi project new")> _
    Public Sub functionsConstructorTest()
        Dim target As functions_Accessor = New functions_Accessor
        Assert.Inconclusive("TODO: Implement code to verify target")
    End Sub
End Class
